﻿Imports System.IO
Imports Training.Common

Partial Public Class EditAnswer
    Inherits System.Web.UI.Page

    Dim aid As Integer ' answerid
    Dim ans As String ' answer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' check for querystring data
        If IsNothing(Request.QueryString("aid")) Or IsNothing(Request.QueryString("ans")) Then
            Response.Redirect("Answers.asxp")
        Else
            aid = Request.QueryString("aid")
            ans = Request.QueryString("ans")
        End If

        ' if its not a postback use querystring answer
        If Not Page.IsPostBack Then
            tbAnswer.Text = ans
        End If
    End Sub

    ''' <summary>
    ''' Update Answer Data
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub UpdateAnswer()
        If UpdateQuizAnswer(aid, tbAnswer.Text) = 0 Then
            lblMsg.Text = "Answer was updated successfully."
        Else
            lblMsg.Text = "Error updating answer, please try again."
        End If
    End Sub

    ''' <summary>
    ''' Delete Answer Data
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub DeleteAnswer()
        DeleteQuizAnswer(aid)
        lblMsg.Text = "Quiz Answer has been deleted."
    End Sub

    ''' <summary>
    ''' Edit button click event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnEdt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdt.Click
        If Page.IsValid Then
            UpdateAnswer()
        End If
    End Sub

    ''' <summary>
    ''' Delete Button click event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnDel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDel.Click
        DeleteAnswer()
    End Sub
End Class